package com.example.haojiutao.service.impl;

import com.example.haojiutao.common.Result;
import com.example.haojiutao.mapper.MessageMapper;
import com.example.haojiutao.model.domain.Message;
import com.example.haojiutao.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageMapper messageMapper;


    /*
     * @Description: 接受消息
     * @Author: wang_meiying
     * @CreateTime: 2024/1/28 20:25
     * @param: message
     * @return: com.example.treasure_box.common.Result
     **/
    @Override
    public Result insertMessage(Message message) {
        message.setMessageTime(new Date());

        int row=messageMapper.insertMessage(message);

        if(row==1){
            return Result.success("消息发送成功");
        }
        return Result.faile("消息发送失败");
    }

    /*
     * @Description: 删除消息
     * @Author: wang_meiying
     * @CreateTime: 2024/1/28 20:26
     * @param: id
     * @return: int
     **/
    @Override
    public int deleteMessage(int id) {
        return messageMapper.deleteMessage(id);
    }

    /*
     * @Description: 查看消息
     * @Author: wang_meiying
     * @CreateTime: 2024/1/28 20:27
     * @param: message
     * @return: com.example.treasure_box.common.Result
     **/
    @Override
    public List<Message> selectMessage(Message message) {
        return messageMapper.selectMessage();
    }

    /*
     * @Description: 根据用户id查看消息
     * @Author: wang_meiying
     * @CreateTime: 2024/1/28 20:28
     * @param: message
     * @return: com.example.treasure_box.common.Result
     **/

    @Override
    public int selectByUserId(int userId) {
        return messageMapper.selectByUserId();
    }
}
